package com.mes.md.controller;

import com.mes.common.pojo.MESResult;
import com.mes.md.service.WorkstationMachineService;
import com.mes.md.service.WorkstationService;
import com.mes.md.service.WorkstationToolService;
import com.mes.md.service.WorkstationWorkerService;
import com.mes.pojo.md.MdWorkstation;
import com.mes.pojo.md.MdWorkstationMachine;
import com.mes.pojo.md.MdWorkstationTool;
import com.mes.pojo.md.MdWorkstationWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author hitsune
 * @Company kafu chino
 * @Description
 * @Time 2024/10/25 16:42
 */

@RestController
@RequestMapping("/workstation")
@CrossOrigin
public class WorkstationController {

    @Autowired
    private WorkstationService workstationService;
    @Autowired
    private WorkstationMachineService workstationMachineService;
    @Autowired
    private WorkstationWorkerService workstationWorkerService;
    @Autowired
    private WorkstationToolService workstationToolService;

    @GetMapping("/list")
    public MESResult queryWorkstationList(MdWorkstation workstation)
    {
        List<MdWorkstation> workstationList = workstationService.queryWorkstationList(workstation);
        return MESResult.success(workstationList);
    }

    @PostMapping("/add")
    public MESResult addWorkstation(@RequestBody MdWorkstation workstation)
    {
        Integer result = workstationService.insertWorkstation(workstation);
        return MESResult.success(result);
    }

    @PostMapping("/update")
    public MESResult updateWorkstation(@RequestBody MdWorkstation workstation)
    {
        Integer result = workstationService.updateWorkstation(workstation);
        return MESResult.success(result);
    }

    @DeleteMapping("/delete")
    public MESResult deleteWorkstation(Long workstationId)
    {
        Integer result = workstationService.deleteWorkstation(workstationId);
        return MESResult.success(result);
    }

    @GetMapping("/queryTools")
    public MESResult queryTools(Long workstationId)
    {
        return MESResult.success(workstationToolService.queryTools(workstationId));
    }

    @GetMapping("/queryWorkers")
    public MESResult queryWorkers(Long workstationId)
    {
        return MESResult.success(workstationWorkerService.queryWorkers(workstationId));
    }

    @GetMapping("/queryMachines")
    public MESResult queryMachines(Long workstationId)
    {
        return MESResult.success(workstationMachineService.queryMachines(workstationId));
    }

    @DeleteMapping("/handleDeleteMachine")
    public MESResult handleDeleteMachine(Long machineryId)
    {
        return MESResult.success(workstationMachineService.deleteMachine(machineryId));
    }

    @DeleteMapping("/handleDeleteWorker")
    public MESResult handleDeleteWorker(Long workerId)
    {
        return MESResult.success(workstationWorkerService.deleteWorker(workerId));
    }

    @DeleteMapping("/handleDeleteTool")
    public MESResult handleDeleteTool(Long toolId)
    {
        return MESResult.success(workstationToolService.deleteTool(toolId));
    }

    @PostMapping("/insertToolWorkstation")
    public MESResult insertToolWorkstation(@RequestBody MdWorkstationTool workstationTool)
    {
        return MESResult.success(workstationToolService.insertTool(workstationTool));
    }

    @PostMapping("/insertWorker")
    public MESResult insertWorker(@RequestBody MdWorkstationWorker workstationWorker)
    {
        return MESResult.success(workstationWorkerService.insertWorker(workstationWorker));
    }

    @PostMapping("/addMachine")
    public MESResult addMachine(@RequestBody MdWorkstationMachine workstationMachine)
    {
        return MESResult.success(workstationMachineService.insertMachine(workstationMachine));
    }
}
